How to sort your records by date.
articles
:
post_date
attribute has dates formatted as strings, which Algolia can’t process for sorting. Before creating a replica, you must transform these dates into Unix timestamps.
You don’t have to remove or change post_date
. Add a post_date_timestamp
attribute with the proper format instead.
articles
index.
The recommendation is to name your replica indices with a prefix or suffix describing its sorting strategy (for example, articles_date_desc
).
First, create a standard or virtual replica (articles_date_desc
) from the primary index.
The primary index is likely sorted by relevance but you want to change that for articles_date_desc
.
post_date_timestamp
attribute to sort the articles_date_desc
virtual index by date in descending order: